package com.mrtan.service.impl;

import com.mrtan.bean.Model;
import com.mrtan.mapper.ModelMapper;
import com.mrtan.service.ModelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品类型
 * @author 李聪
 * @version 2023/12/8
 */
@Service
public class ModelServiceImpl implements ModelService {

    @Resource
    private ModelMapper modelMapper;

    /**
     * 模糊查询
     * @param name
     * @return {@link List}<{@link Model}>
     */
    @Override
    public List<Model> findByName(String name) {
        List<Model> models = modelMapper.selectAll(name);
        return models;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void removeById(int id) {
        modelMapper.deleteByPrimaryKey(id);
    }

    /**
     * 添加种类
     * @param name
     * @return int
     */
    @Override
    public int addModel(String name) {
        // 查重
        Model model = modelMapper.selectByName(name);
        if(model!=null){
            return -1;
        }
        int insert = modelMapper.insert(name);

        return insert;
    }
}
